<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<md-table-container style="height: 100%;" class="gravitee-widget-table">
  <table md-table class="gravitee-analytics-top-hits-table gv-table-dense" multiple md-row-select="$ctrl.widget.chart.selectable" data-ng-model="$ctrl.selected">
    <thead md-head>
      <tr md-row style="height: 30px;">
        <th md-column ng-repeat="column in $ctrl.widget.chart.columns" ng-attr-md-numeric="$last">{{column}}</th>
        <th md-column ng-if="$ctrl.widget.chart.percent" ng-attr-md-numeric>Percent</th>
      </tr>
    </thead>
    <tbody md-body>
      <tr ng-if="$ctrl.results.length > 0" md-row
          ng-repeat="result in $ctrl.results | limitTo: $ctrl.widget.chart.paging: ($ctrl.paging - 1) * $ctrl.widget.chart.paging | orderBy:'metadata.order'"
          md-select="result" md-select-id="key" style="height: 25px;"
          md-on-select="$ctrl.selectItem" md-on-deselect="$ctrl.deselectItem">
        <td md-cell>
          <a ng-if="!result.metadata.deleted && !result.metadata.unknown && $ctrl.isClickable(result)" ng-click="$ctrl.goto(result.key)">
            {{result.metadata.name}} <small ng-if="result.metadata.version">({{result.metadata.version}})</small>
          </a>

          <span ng-if="!result.metadata.deleted && !$ctrl.isClickable(result)" >
            {{result.metadata.name}} <small ng-if="result.metadata.version">({{result.metadata.version}})</small>
          </span>

          <span ng-if="result.metadata.deleted" style="color: grey;">
            {{result.metadata.name}}
          </span>
        </td>
        <td md-cell>{{result.value | number}}</td>
        <td md-cell ng-if="$ctrl.widget.chart.percent">{{result.percent | number}}%</td>
      </tr>
      <tr ng-if="$ctrl.results.length === 0">
        <td md-cell colspan="{{($ctrl.widget.chart.percent ? 3 : 2) + (($ctrl.widget.chart.selectable) ? ($ctrl.widget.chart.percent ? 2 : 1) : ($ctrl.widget.chart.percent ? 1 : 0))}}">No result</td>
      </tr>
    </tbody>
  </table>
</md-table-container>
<md-table-pagination class="gravitee-widget-pagination"
  md-limit="$ctrl.widget.chart.paging" md-page="$ctrl.paging" md-total="{{$ctrl.results.length}}"></md-table-pagination>
